package com.ctsi.offlinesupport.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.supportflow.app.entity.SupportFiles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * SupportFiles Service 类
 * @author   liuhx
 * @description  SupportFiles
 * @created	 Wed Nov 14 11:28:14 CST 2018
 */

@Service
public class SupportFilesService {
	private static final Logger logger=LoggerFactory.getLogger(SupportFilesService.class);
	@Autowired
	private MybatisGenericDao dao;
	
	/**
	 * 添加
	 */
	public void insertSupportFiles(SupportFiles supportFiles){
		if(UtilValidate.isEmpty(supportFiles.getId()))
			supportFiles.setId(UUIDGenerator.getId());
		logger.debug("insert {}",supportFiles);
		dao.insert(supportFiles);
	}	
	/**
	 * 动态更新
	 */	
	public int updateSupportFilesByPKSelective(SupportFiles supportFiles){
		logger.debug("updateByPrimaryKeySelective {}",supportFiles);
		return dao.update(SupportFiles.class.getName()+".updateByPrimaryKeySelective", supportFiles);
	}
	/**
	 * 更新
	 */
	public int updateSupportFiles(SupportFiles supportFiles){
		logger.debug("update {}",supportFiles);
		return dao.update(supportFiles);
	}
	
	
	public SupportFiles editSupportFilesById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("editById {}",id);
		return (SupportFiles)dao.queryForObject(SupportFiles.class.getName()+".edit", id);
	}
	/**
	 * 根据ID查找 SupportFiles对象
	 */
	public SupportFiles findSupportFilesById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(SupportFiles.class, id);
	}
	/**
	 * 删除SupportFiles对象
	 */
	public int removeSupportFiles(String id){	
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(SupportFiles.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}
	
	/**
	 * 详细页查询
	 */
	public SupportFiles findByDetail(String id){
		return (SupportFiles)dao.queryForObject(SupportFiles.class.getName()+".findByDetail",id);
	}
	/** 
	 * 多条件查询结果 
	 */
	public Page<SupportFiles> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(SupportFiles.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/** 
	 * 多条件查询结果不分页
	 */
	public List<SupportFiles> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<SupportFiles>)dao.queryForList(SupportFiles.class.getName()+".selectByMap",map);
	}

    /**
     * 获取附件信息
     * @param adjunctId
     * @return
     */
	public SupportFiles getFilesByAdjunctId(String adjunctId){
        return (SupportFiles) dao.queryForObject(SupportFiles.class.getName()+".getFilesByAdjunctId", adjunctId);
    }
	
}
